﻿namespace EMall
{
    public static class Check
    {
        public static T IsNull<T>(T? value, string parameterName)
        {
            return value ?? throw new ArgumentNullException(parameterName);
        }
        public static string IsNullOrEmpty(string? value, string parameterName)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentException(parameterName + " cannot be null or empty!", parameterName);
            }
            return value;
        }
        public static string IsNullOrWhiteSpace(string? value, string parameterName)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new ArgumentException(parameterName + " cannot be null, empty or white space!", parameterName);
            }
            return value;
        }
        public static short Positive(short value, string parameterName)
        {
            if (value == 0)
            {
                throw new ArgumentException(parameterName + " cannot equal to zero");
            }
            if (value < 0)
            {
                throw new ArgumentException(parameterName + " cannot less than zero");
            }
            return value;
        }
        public static int Positive(int value, string parameterName)
        {
            if (value == 0)
            {
                throw new ArgumentException(parameterName + " cannot equal to zero");
            }
            if (value < 0)
            {
                throw new ArgumentException(parameterName + " cannot less than zero");
            }
            return value;
        }
        public static long Positive(long value, string parameterName)
        {
            if (value == 0L)
            {
                throw new ArgumentException(parameterName + " cannot equal to zero");
            }
            if (value < 0)
            {
                throw new ArgumentException(parameterName + " cannot less than zero");
            }
            return value;
        }
        public static float Positive(float value, string parameterName)
        {
            if (value == 0f)
            {
                throw new ArgumentException(parameterName + " cannot equal to zero");
            }
            if (value < 0f)
            {
                throw new ArgumentException(parameterName + " cannot less than zero");
            }
            return value;
        }
        public static double Positive(double value, string parameterName)
        {
            if (value == 0.0)
            {
                throw new ArgumentException(parameterName + " cannot equal to zero");
            }
            if (value < 0.0)
            {
                throw new ArgumentException(parameterName + " cannot less than zero");
            }
            return value;
        }
        public static decimal Positive(decimal value, string parameterName)
        {
            if (value == 0m)
            {
                throw new ArgumentException(parameterName + " cannot equal to zero");
            }
            if (value < 0m)
            {
                throw new ArgumentException(parameterName + " cannot less than zero");
            }
            return value;
        }
        public static short Range(short value, string parameterName, short minimumValue = 0, short maximumValue = short.MaxValue)
        {
            if (value < minimumValue || value > maximumValue)
            {
                throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
            }
            return value;
        }
        public static int Range(int value, string parameterName, int minimumValue = 0, int maximumValue = int.MaxValue)
        {
            if (value < minimumValue || value > maximumValue)
            {
                throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
            }
            return value;
        }
        public static long Range(long value, string parameterName, long minimumValue = 0L, long maximumValue = long.MaxValue)
        {
            if (value < minimumValue || value > maximumValue)
            {
                throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
            }
            return value;
        }
        public static float Range(float value, string parameterName, float minimumValue = 0f, float maximumValue = float.MaxValue)
        {
            if (value < minimumValue || value > maximumValue)
            {
                throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
            }
            return value;
        }
        public static double Range(double value, string parameterName, double minimumValue = 0.0, double maximumValue = double.MaxValue)
        {
            if (value < minimumValue || value > maximumValue)
            {
                throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
            }
            return value;
        }
        public static decimal Range(decimal value, string parameterName, decimal minimumValue = 0m, decimal maximumValue = decimal.MaxValue)
        {
            if (value < minimumValue || value > maximumValue)
            {
                throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
            }
            return value;
        }
    }
}
